import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

/* *************  登录页面 ***************** */
import Login from '../src/components/log_page/Login.vue'
import Regiter from '../src/components/log_page/Regiter.vue'

/* *************  manager 页面 ***************** */
import Manager from '../src/components/Manager.vue'


/* *************  main 页面 ***************** */
import Main from '../src/components/main_page/Main.vue'
import MainFirstPage from '../src/components/main_page/MainFirstPage.vue'
import ArticleDetail from '../src/components/main_page/ArticleDetail.vue'


/* *************  header 页面 ***************** */
import HotSearchBord from '../src/components/header/HotSearchBord.vue'
import PrivateSend from '../src/components/header/PrivateSend.vue'


/* *************  footer 页面 ***************** */
import Ask from '../src/components/footer/Ask.vue'
import Suggest from '../src/components/footer/Suggest.vue'

/* *************  person 页面 ***************** */
import PersonPage from '../src/components/person_page/PersonPage.vue'
import ModifyInfo from '../src/components/person_page/ModifyInfo.vue'
import ArticleInfo from '../src/components/person_page/ArticleInfo.vue'
import Article from '../src/components/person_page/Article.vue'
import CareAbout from '../src/components/person_page/CareAbout.vue'
import Fans from '../src/components/person_page/Fans.vue'
import MyCollections from '../src/components/person_page/MyCollections.vue'
import History from '../src/components/person_page/History.vue'




/**************************  后台管理 **************************/
import BehindManager from '../src/components/behind/BehindManager.vue'
import bHeader from '../src/components/behind/bHeader.vue'
import UserAccountMag from '../src/components/behind/UserAccountMag.vue'
import ArticleMag from '../src/components/behind/ArticleMag.vue'
import RunData from '../src/components/behind/RunData.vue'
import PostNotice from '../src/components/behind/PostNotice.vue'
import DetailInfo from '../src/components/behind/DetailInfo.vue'

var router=new VueRouter({
	mode:'history',
	routes:[
		{
			path:'/log',
			component:Login
		},
		{
		   	path:'/register',
			component:Regiter
		},
		{
			path:'/behind',
			name:'behind',
			component:BehindManager,
			children:[
				{
					path:'useraccountmag',
					name:'useraccountmag',
					component:UserAccountMag,
					children:[
						{
							path:'detailinfo',
							name:'detailinfo',
							component:DetailInfo
						}
					]
				},
				{
					path:'articlemag',
					name:'articlemag',
					component:ArticleMag
				},
				{
					path:'rundata',
					name:'rundata',
					component:RunData
				},
				{
					path:'postnotice',
					name:'postnotice',
					component:PostNotice
				}
			]
		},
		{
			path:'/manager',
			component:Manager,
			children:[
				{
					name:'main',
					path:'main',
					component:Main,
					children:[
						{
							name:'privatesend',
							path:'privatesend',
							component:PrivateSend
						},
						{
							name:'hotsearchbord',
							path:'hotsearchbord',
							component:HotSearchBord
						},
						{
							name:'mainfirstpage',
							path:'mainfirstpage',
							component:MainFirstPage,
						},
						{
							name:'articledetail',
							path:'articledetail/:cnickname',
							component:ArticleDetail,
							props:true
						},
						{
							name:'ask',
							path:'ask',
							component:Ask
						},
						{
							name:'suggest',
							path:'suggest',
							component:Suggest
						},
					]
				},
				{
					name:'personpage',
					path:'personpage',
					component:PersonPage,
					children:[
						{
							name:'modify',
							path:'modify',
							component:ModifyInfo
						},
						{
							name:'articleinfo',
							path:'articleinfo',
							component:ArticleInfo,
							children:[
								{
									name:'article',
									path:'article',
									component:Article
								},
								{
									name:'careabout',
									path:'careabout',
									component:CareAbout
								},
								{
									name:'fans',
									path:'fans',
									component:Fans
								},
								{
									name:'mycollections',
									path:'mycollections',
									component:MyCollections
								},
								{
									name:'history',
									path:'history',
									component:History
								}
							]
						}
					]
				},
			]
		}
	]
})

router.beforeEach(function(to,from,next){
	console.log('------- from.path --------   ',from.path);
	console.log('------- to--------   ',to.path); 
	
	// 对于后台管理员，路由允许通过
	if(to.path=='/behind/useraccountmag'||to.path=='/behind/articlemag'||to.path=='/behind/rundata'||to.path=='/behind/postnotice'){
		console.log('进入后台管理-------');
		next();
	}
	// 对于用户，需要校验用户信息
	else{
		if(from.path=='/'||from.path=='/log'){
			next();
		}
		else{
			var nickname=window.sessionStorage.getItem('nickname');
			if(nickname){
				// console.log('找到 用户 ',nickname);
				next();
			}else{
				console.log('请先登录 !!!!!!');
				location.href='http://localhost:8080/log';
			}
		}
	}
})

export default router





